package com.nc.solutions.rentacar.manager.Impl;

import com.nc.solutions.rentacar.domain.tariff.ITariff;
import com.nc.solutions.rentacar.domain.car.ICar;
import com.nc.solutions.rentacar.domain.tariff.impl.Tariff;
import com.nc.solutions.rentacar.manager.ITariffManager;

import java.util.Map;
import java.util.TreeMap;

public class TariffManager implements ITariffManager {
    private Map<Integer, ITariff> tariffList;

    public TariffManager() {
        tariffList = new TreeMap<Integer, ITariff>();
    }

    public ITariff getTariffByProduct(ICar car) {
        return tariffList.get(car.getID());
    }

    public ITariff getTariffByProductId(long id) {
        return tariffList.get(id);
    }

    public ITariff newTariff(ICar car) {
        ITariff tariff = new Tariff(car);
        tariffList.put((int)car.getID(), tariff);
        return tariff;
    }

    @Override
    public boolean removeTariffOfCar(ICar car) {
        return tariffList.remove(car.getID()) != null;
    }
}
